package javaTest05.exercise01.tcp;

import javaTest05.utils.FileUtils;

import java.io.*;
import java.net.Socket;
import java.time.LocalDateTime;

public class TcpClient {
    public static void main(String[] args) {
        try {
            Socket severSocket = new Socket("localhost", 1024);
            System.out.println("与服务端" + severSocket.getRemoteSocketAddress() + "连接成功" + LocalDateTime.now());
            OutputStream out = severSocket.getOutputStream();
            byte[] fileBuffer = FileUtils.getByteArrayFromFile("src/javaTest05/resource/my.docx",false);

            if (fileBuffer == null) {
                System.out.println("文件读取异常...");
            }
            else {
                out.write(fileBuffer);
                System.out.println("成功上传文件");
            }

            out.flush();
            out.close();
            severSocket.close();

        } catch (IOException e) {
            e.printStackTrace();
        }
    }




}
